import api from '../../api'
export default {
    state: {
        films: [],
        detail: {}
    },
    mutations: {
        getFilms(state, data) {
            // if (this.films.length > 0) {
            //     this.pageNum++;
            //     if (pos === 0) {
            //         this.films = [...ret.data.films, ...this.films];
            //     } else {
            //         this.films = [...this.films, ...ret.data.films];
            //     }
            // }
            state.films = [...state.films, ...data]
        },
        getFilmInfo(state, data) {
            state.detail = data
        },
        cleanFilms(state) {
            state.films = []
        }
    },
    actions: {
        async getFilms({ commit }, data) {
            console.log(data.pageNum);
            let ret = await api.getNowPlayingFilmList(data)
            // console.log(ret.pageNum);
            
            commit('getFilms', ret.data.films)
            // console.log(ret.data)
        },
        async getFilmInfo({ commit }, data) {
            let ret = await api.getFilmInfo(data)

            commit('getFilmInfo', ret.data.film)
        }
    }
}